package br.com.fcomota.pi_iv_sie.dao;

import br.com.fcomota.pi_iv_sie.*;
import br.com.fcomota.pi_iv_sie.modelo.Usuario;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by Francisco Mota.
 */
public class Dao_Novo_Cad_Usuario_Activity extends Activity {
	private Usuario usuario = new Usuario();
	private EditText nomeEt;
	private EditText senhaEt;
	private Button salvarBt;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_novo_usuario);
		
		nomeEt = (EditText) findViewById(R.id.nome);
		senhaEt = (EditText) findViewById(R.id.senha);
		salvarBt = (Button) findViewById(R.id.button1);
		
		
		Intent intent = getIntent();
		if(intent != null){
			Bundle bundle = intent.getExtras();
			if(bundle != null){
				
				usuario.setId(bundle.getLong("id"));
				usuario.setNome(bundle.getString("nome"));
				
				nomeEt.setText(usuario.getNome());
				
				senhaEt.setVisibility(View.GONE);
				salvarBt.setVisibility(View.GONE);
			}
		}
	}
	
	
	public void salvarUsuario(View view){
		usuario.setNome(nomeEt.getText().toString());
		usuario.setSenha(senhaEt.getText().toString());

		BD_SQLite_Usuario BDSQLiteUsuario = new BD_SQLite_Usuario(this);
		BDSQLiteUsuario.inserir(usuario);

		Toast.makeText(this, "Usuario inserido com sucesso!", Toast.LENGTH_SHORT).show();
	}

}
